#ifndef ACCELEROMETER_CALIBRATION_H_
#define ACCELEROMETER_CALIBRATION_H_
#include <stdint.h>
#include <stdbool.h>

#define    X_ACCEL_BIAS                       0.0442318916f
#define    Y_ACCEL_BIAS												-0.0457367897f
#define    Z_ACCEL_BIAS												-0.208868027f
#define    X_ACCEL_SCALE											1.00059092f
#define    Y_ACCEL_SCALE											1.00055051f
#define    Z_ACCEL_SCALE											0.99191761f


#define     ACCEL_CALIBRA_START               0
#define     DETECT						                1
#define			NOSE_UP							  						2
#define     NOSE_DOWN						 						  3
#define     LEFT_SIDE_DOWN					  				4
#define     RIGHT_SIDE_DOWN					  				5
#define			ON_BACK							  						6
#define     LEVEL							  							7
#define     SAMPLE_FINISHED                   8
#define     CAL_OFFS						  						9
#define     CAL_SCALE                         10
#define     CAL_DONE                          11

#define    	SAMPLELENGTH											500

typedef struct _accel_calibrate_t {
	
	uint8_t routines;
	
	bool calibrate_init;
	
	bool nose_up_sampling;
	bool nose_up_finished;
	bool nose_up_calibrated;
	
	bool nose_down_sampling;
	bool nose_down_finished;
	bool nose_down_calibrated;
	
	bool left_side_down_sampling;
	bool left_side_down_finished;
	bool left_side_down_calibrated;
	
	bool right_side_down_sampling;
	bool right_side_down_finished;
	bool right_side_down_calibrated;
	
	bool on_back_sampling;
	bool on_back_finished;
	bool on_back_calibrated;
	
	bool level_sampling;
	bool level_finished;
	bool level_calibrated;
	
	bool accel_calibration_finished;
	
	float x_scale;
	float y_scale;
	float z_scale;

	float x_offset;
	float y_offset;
	float z_offset;
	
}_accel_calibrate;


typedef struct _accel_calibration_sample_buffer {

	float avg_buffer[6][3];

	float x_accel_sum;
	float y_accel_sum;
	float z_accel_sum;
	
	uint16_t index;

}accel_calibration_sample_buffer;

void accel_calibration_task(void);

#endif
